package com.xopencode.io;

import java.io.*;
import java.nio.channels.FileChannel;

/**
 * @author Mcb
 * @date 2022/5/4
 * @apiNote
 */
public class CopyTest02 {
    public static void main(String[] args) throws IOException {
        File file = new File("test.jpg");
        File fileCopy = new File("Copy3.jpg");

        FileInputStream inputStream = new FileInputStream(file);
        FileChannel channel = inputStream.getChannel();

        FileOutputStream outputStream = new FileOutputStream(fileCopy);
        FileChannel copyChannel = outputStream.getChannel();
        /*//对于当前通道来说，把当前通道数据to参数通道
        channel.transferTo(0,channel.size(),copyChannel);*/
        //对于当前通道来说，From指定通道获取数据到当前通道
        copyChannel.transferFrom(channel,0,channel.size());
        System.out.println("复制成功");
    }
}
